/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TMP.ac.acpcland;

import TMP.ac.acpcland.NewJInternalFrame;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.AncestorListener;
import tmp.ac.lib.tools.DBClass;
import ac.uitls.propertiesOperation;
import tmp.ac.lib.tools.uiUtil;
import tmp.ac.lib.tools.util;
import tmp.ac.myInterface.myIndex;
import tmp.ac.options.DataFrame;
/*import ac.test.NewJFrame;
 import ac.test.NewMDIApplication;*/
import java.awt.ComponentOrientation;

/**
 *
 * @author ismail
 */
public class mian extends javax.swing.JFrame {

    /**
     * Creates new form mian
     */
    myIndex index = new myIndex();
    propertiesOperation po = new propertiesOperation();
    uiUtil UIU = new uiUtil();

    public mian() {
        initComponents();
        try {
            mainUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(mian.class.getName()).log(Level.SEVERE, null, ex);
        }
        jSplitP.setDividerLocation(30);


    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        menuPn = new javax.swing.JPanel();
        catHeader = new javax.swing.JPanel();
        catBody = new javax.swing.JPanel();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jSplitP = new javax.swing.JSplitPane();
        End = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        menu_bt = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jToolBar2 = new javax.swing.JToolBar();
        jToolBar3 = new javax.swing.JToolBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        menuPn.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 0), 3));

        catHeader.setBorder(javax.swing.BorderFactory.createBevelBorder(0));
        catHeader.setPreferredSize(new java.awt.Dimension(75, 49));

        javax.swing.GroupLayout catHeaderLayout = new javax.swing.GroupLayout(catHeader);
        catHeader.setLayout(catHeaderLayout);
        catHeaderLayout.setHorizontalGroup(
            catHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 71, Short.MAX_VALUE)
        );
        catHeaderLayout.setVerticalGroup(
            catHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 499, Short.MAX_VALUE)
        );

        catBody.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        catBody.setLayout(new java.awt.BorderLayout());

        javax.swing.GroupLayout menuPnLayout = new javax.swing.GroupLayout(menuPn);
        menuPn.setLayout(menuPnLayout);
        menuPnLayout.setHorizontalGroup(
            menuPnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(menuPnLayout.createSequentialGroup()
                .addComponent(catHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(catBody, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        menuPnLayout.setVerticalGroup(
            menuPnLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(catHeader, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
            .addComponent(catBody, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jSplitPane1.setLeftComponent(menuPn);
        menuPn.getAccessibleContext().setAccessibleDescription("");

        jSplitPane1.setRightComponent(jDesktopPane1);

        jSplitP.setDividerLocation(250);
        jSplitP.setDividerSize(10);
        jSplitP.setAutoscrolls(true);
        jSplitP.setContinuousLayout(true);
        jSplitP.setPreferredSize(new java.awt.Dimension(226, 35));

        End.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        End.setForeground(new java.awt.Color(255, 0, 51));
        End.setText("X");
        End.setAlignmentX(0.5F);
        End.setFocusable(false);
        End.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        End.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        End.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EndActionPerformed(evt);
            }
        });
        jSplitP.setLeftComponent(End);

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jToolBar1.setDoubleBuffered(true);
        jToolBar1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jToolBar1MouseClicked(evt);
            }
        });

        menu_bt.setText("menu_bt");
        menu_bt.setFocusable(false);
        menu_bt.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        menu_bt.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menu_bt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_btActionPerformed(evt);
            }
        });
        jToolBar1.add(menu_bt);
        jToolBar1.add(jSeparator1);

        jToolBar2.setBackground(new java.awt.Color(102, 102, 102));
        jToolBar2.setAutoscrolls(true);
        jToolBar1.add(jToolBar2);

        jToolBar3.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jToolBar1.add(jToolBar3);

        jSplitP.setRightComponent(jToolBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSplitP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE))
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jSplitP, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mainUpdate() throws SQLException {

        updateMeun();
        //uiUtil.sendMessage(End, sesstionData.userID, sesstionData.userID);
        UIU.updatepanelWords(jToolBar1.getParent().getComponents());
        menuPn.setVisible(false);
        this.setSize(new Dimension(600, 400));
        if (po.getProperty("lang").equalsIgnoreCase("ar")) {
            this.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        }




    }

    private void updateMeun() throws SQLException {


        ArrayList<String> importData = index.getMenuCategories();


        int top = 0;
        for (String mcatItems : importData) {
            final JPanel body = new JPanel();
            final String[] mcatItem = mcatItems.split(";");
            javax.swing.JButton b = new javax.swing.JButton(po.getWord("label." + mcatItem[1]));

            b.setLocation(3, top * 73 + 3);
            b.setSize(new Dimension(70, 40));

            b.addMouseListener(new MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    for (int i = 0; i < catBody.getComponentCount(); i++) {

                        catBody.getComponent(i).setVisible(false);
                        body.setVisible(true);
                        if (mcatItem.length > 3) {

                            menuPn.setBorder(javax.swing.BorderFactory.createLineBorder(Color.decode("#" + mcatItem[3]), 3));

                        } else {

                            menuPn.setBorder(javax.swing.BorderFactory.createLineBorder(Color.decode("000000"), 3));


                        }

                    }


                }
            });



            catHeader.add(b);
            catHeader.repaint();


            if (mcatItem.length > 3) {
                b.setBackground(Color.decode("#" + mcatItem[3]));
                // body.setBorder(javax.swing.BorderFactory.createLineBorder(Color.decode(mcatItem[3]), 3));

            }

            body.setSize(catBody.getSize());





            ArrayList<String> Items = index.getMenuIemes(mcatItem[0]);

            for (String item : Items) {


                final String[] items = item.split(";");


                javax.swing.JButton bitem = new javax.swing.JButton();
                bitem.setText(" " + (po.getWord("label." + items[3])) + " ");


                //bitem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/setting_menu.png")));


                bitem.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(java.awt.event.MouseEvent evt) {
                        if (items[7].equals("0")) {
                            UIU.openWindows(DataFrame.getFrame(items[5]), Integer.parseInt(items[8]), Integer.parseInt(items[9]));

                        } else {
                            try {
                                UIU.SetjDesktopPane(jDesktopPane1);
                                UIU.SetjToolBar(jToolBar2);
                                UIU.openMidWindows(DataFrame.getIFrame(items[5]), items[3]);



                            } catch (IOException ex) {
                                Logger.getLogger(mian.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }



                        menuPn.setVisible(false);

                    }
                });




                bitem.setLocation(3, top * 73 + 3);
                bitem.setSize(new Dimension(45, body.getWidth()));
                body.add(bitem);

            }




            catBody.add(body);

            catBody.repaint();
            top++;
        }

    }

    private void menu_btActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menu_btActionPerformed







        if (menuPn.isVisible()) {
            jSplitPane1.setDividerLocation(0);
            menuPn.setVisible(false);
        } else {
            menuPn.setVisible(true);
            jSplitPane1.setDividerLocation(250);


        }




    }//GEN-LAST:event_menu_btActionPerformed
    private void EndActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EndActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_EndActionPerformed

    private void jToolBar1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToolBar1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jToolBar1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;


                }
                // UIManager.setLookAndFeel("com.jtattoo.plaf.smart.HiFiLookAndFeel");
                // UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");




            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(mian.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(mian.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(mian.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(mian.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new mian().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton End;
    private javax.swing.JPanel catBody;
    private javax.swing.JPanel catHeader;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JSplitPane jSplitP;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JPanel menuPn;
    private javax.swing.JButton menu_bt;
    // End of variables declaration//GEN-END:variables
}
